﻿using System;
using System.Collections.Generic;
using System.Collections;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Telerik.Web.UI;
using KPIS.GERP.GHRMS.BLL;
using KPIS.GERP.GHRMS.IBLL;
using KPIS.GERP.GHRMS.MODEL;
using KPIS.DBM;

namespace KPIS.GERP.GHRMS.APP.App_UI.UserControls
{
    public partial class PR_BudgetManagements : System.Web.UI.UserControl
    {
        private SsMng ssMng = new SsMng();
        private BudgetManagementTestBLL mngBLL = new BudgetManagementTestBLL();

        private object _dataItem = null;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (DataItem != null)
            {
                if (!(DataItem is Telerik.Web.UI.GridInsertionObject))
                {
                    //lblSeq.Text = DataBinder.Eval(DataItem, "Sequence").ToString();
                    //txtName.Text = DataBinder.Eval(DataItem, "Name").ToString();
                    //txtNameEng.Text = DataBinder.Eval(DataItem, "NameEng").ToString();
                }
            }
        }

        public object DataItem
        {
            get
            {
                return this._dataItem;
            }
            set
            {
                this._dataItem = value;
            }
        }

        protected void btnAddnew_Click(object sender, EventArgs e)
        {
            //regionBLL.Insert(txtName.Text.Trim()
            //    , txtNameEng.Text.Trim()
            //    , 1);
        }

        protected void btnUpdate_Click(object sender, EventArgs e)
        {
            if (lblSequence.Text.Length > 0)
            {
                mngBLL.UpdateManagement(Int32.Parse(lblSequence.Text)
                    , double.Parse(txtPercent.Text)
                    , double.Parse(txtAmount.Text)
                    , double.Parse(txtAmountNet.Text)
                    , ssMng.EmpSeqI);
            }
            else 
            {
                int PrmSeq = mngBLL.GetPrmPromotionSeq(Int32.Parse(Session["EmpTypeSeq"].ToString())
                    , Int32.Parse(Session["BGYear"].ToString())
                    , Int32.Parse(Session["Period"].ToString()));

                mngBLL.InsertManagement(PrmSeq
                    , Int32.Parse(lblJobSiteSeq.Text)                    
                    , double.Parse(txtPercent.Text)
                    , double.Parse(txtAmount.Text)
                    , double.Parse(txtAmountNet.Text)
                    , ssMng.EmpSeqI);
            }
        }

        protected void btnCancel_Click(object sender, EventArgs e)
        {

        }

        protected void txtPercent_TextChanged(object sender, EventArgs e)
        {
            if (txtPercent.Text.Trim().Length <= 0)
                return;

            double nPercent = Convert.ToDouble(txtPercent.Text);
            txtAmount.Text = string.Format("{0:N2}", nPercent * mngBLL.GetSumBudget(Int32.Parse(lblJobSiteSeq.Text)
                                , Int32.Parse(Session["EmpTypeSeq"].ToString())
                                , Int32.Parse(Session["BGYear"].ToString())
                                , Int32.Parse(Session["Period"].ToString()))
                                / 100);
        }
    }
}